package com.pojoin.cms.util.criteria.orderby;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class Orderby {

	/**
	 * map key为要排序字段,value为升序或降序
	 *     value 为  OrderbyCost.ASC(升序) 或 OrderbyCost.DESC(降序) 
	 */
	private Map<String,String> map=new HashMap<String,String>();

	public Orderby(String field,final String ASCORDESC){
		map.put(field,ASCORDESC);
	}
	public void addOrderField(String field,final String ASCORDESC){
		map.put(field,ASCORDESC);
	}
	public String getSQL(){
		String str=" order by ";
		String kongge=" ";
		String daohao=",";
		StringBuffer sql=new StringBuffer(str);
		Set<String> keys=map.keySet();
		for(String key:keys){
			sql.append(key).append(kongge).append(map.get(key)).append(daohao);
		}
		int end=sql.lastIndexOf(daohao);
		sql.deleteCharAt(end);
		return sql.toString();
	}
}
